FROM centos:latest
LABEL "lijiasen" <lijiasen@chinacnd.com>
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
RUN localedef -c -i zh_CN -f UTF-8 zh_CN.UTF-8
ENV LC_ALL "zh_CN.UTF-8"  

ENV MYSQL_PACKAGE mysql-community-server-minimal-5.7.21-1.el7.x86_64
ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-5.7-community/docker/x86_64/${MYSQL_PACKAGE}.rpm

RUN yum install -y wget
RUN wget ${PACKAGE_URL}

# Install server
RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql \
  && yum install -y ${MYSQL_PACKAGE}.rpm \
  && yum install -y libpwquality \
  && rm -rf /var/cache/yum/*r
RUN rm -f ${MYSQL_PACKAGE}.rpm
VOLUME /var/lib/mysql

RUN yum -y install python-setuptools python-setuptools-devel
RUN easy_install supervisor
RUN mkdir -p /var/log/supervisor

COPY conf/supervisor.conf /etc/supervisord.conf

#定义会被容器自动执行的目录
ENV AUTO_RUN_DIR /docker-entrypoint-initdb.d

RUN mkdir $AUTO_RUN_DIR
#定义工作目录
ENV WORK_PATH /home/sql
RUN mkdir -p ${WORK_PATH}
#定义sql文件名
ENV FILE_START 0、start.sql
ENV FILE_0 0、horizon_ddl.sql
ENV FILE_1 1、horizon_dml - 00平台.sql
ENV FILE_2 1、horizon_dml - 01工作流.sql
ENV FILE_3 1、horizon_dml - 02报表.sql
ENV FILE_4 1、horizon_dml - 03参数.sql
ENV FILE_5 1、horizon_dml - 04编码规则.sql
ENV FILE_6 1、horizon_dml - 05菜单.sql
ENV FILE_7 1、horizon_dml - 06代码表.sql
ENV FILE_8 1、horizon_dml - 07异常配置.sql
ENV FILE_END 9、end.sql
COPY sql/${FILE_START} ${WORK_PATH}/
COPY sql/${FILE_0} ${WORK_PATH}/
COPY sql/${FILE_1} ${WORK_PATH}/
COPY sql/${FILE_2} ${WORK_PATH}/
COPY sql/${FILE_3} ${WORK_PATH}/
COPY sql/${FILE_4} ${WORK_PATH}/
COPY sql/${FILE_5} ${WORK_PATH}/
COPY sql/${FILE_6} ${WORK_PATH}/
COPY sql/${FILE_7} ${WORK_PATH}/
COPY sql/${FILE_8} ${WORK_PATH}/
COPY sql/${FILE_END} ${WORK_PATH}/

COPY init_data.sh ${AUTO_RUN_DIR}
#给执行文件增加可执行权限
RUN chmod a+x $AUTO_RUN_DIR/init_data.sh

COPY docker-entrypoint.sh /entrypoint.sh
RUN chmod 777 /entrypoint.sh
COPY ./conf/my.cnf /etc/my.cnf

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 3306 9001

CMD ["mysqld"]
